package com.cictec.middleware.tde.rm.protocol.rm.decode;

import java.nio.ByteBuffer;

import org.apache.mina.core.session.IoSession;

import com.cictec.middleware.commons.utils.BinaryUtils;
import com.cictec.middleware.tde.exception.MessageDecoderException;
import com.cictec.middleware.tde.rm.protocol.AbstractMessageDecoder;
import com.cictec.middleware.tde.rm.protocol.TerminalMessage;
import com.cictec.middleware.tde.rm.protocol.TerminalMessage.Header;
import com.cictec.middleware.tde.rm.protocol.annotion.TerminalMessageDecoder;
import com.cictec.middleware.tde.rm.protocol.rm.message.Rm0x08TerminalMessage;
import com.cictec.middleware.tde.rm.protocol.rm.utils.RmBinaryUtils;

/**
 * 0x08 关机消息
 * @author Zhibin
 *
 */
@TerminalMessageDecoder(0x08)
public class Rm0x08Decoder extends AbstractMessageDecoder {

	@Override
	public TerminalMessage decode(Header header, ByteBuffer in, IoSession session) throws MessageDecoderException {

		Rm0x08TerminalMessage msg = new Rm0x08TerminalMessage(header);
		msg.setCreateTime(RmBinaryUtils.dwordToDateRM(in));
		msg.setReson(BinaryUtils.unsignedByteToInt(in));
		msg.setReserved(BinaryUtils.wordToInt(in));

		return msg;
	}

}
